package com.example.kafka.controller;

import com.example.kafka.service.KafkaProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @application:
 * @author: LiYuhang
 * @Date: 2021/4/11 21:11
 * @version: 0.1
 * @Description :
 * @Modified By:
 */
@RestController
@RequestMapping(value = "/kafka")
public class KafkaController {

    private final KafkaProducer kafkaProducer;

    @Autowired
    public KafkaController(KafkaProducer kafkaProducer) {
        this.kafkaProducer = kafkaProducer;
    }

    @PostMapping(value = "/send")
    public void sendMsg(@RequestBody String msg){
        kafkaProducer.send(msg);
    }
}
